package com.base.web.auth.controller;

import com.base.web.auth.service.LogService;
import com.base.web.core.common.JsonResult;
import com.base.web.model.master.auth.Log;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description: 日志控制层
 *
 * @Author: RenTie
 * @Date: 2018-08-17 10:26
 **/
@RestController
@RequestMapping("/log")
public class LogController {

    private Logger logger = LoggerFactory.getLogger(LogController.class);

    @Autowired
    private LogService logService;

    /**
     * 查询日志列表
     *
     * @param map page   当前页
     *            limit 每页个数
     *            response 响应状态
     *            startTime 请求时间开始
     *            endTime 请求时间结束
     * @return
     */
    @GetMapping("/list")
    public JsonResult list(@RequestParam Map<String, String> map) {
        PageInfo<Log> list = null;
        try {
            list = logService.select(map);
        } catch (Exception e) {
            logger.error("查询日志异常={}", e.getMessage());
            return JsonResult.fail("查询日志异常");
        }
        return JsonResult.success(list.getList(), list.getTotal());
    }
}
